/*
 * Powered By XY
 * Since 2020
 */

package com.xy.biz.uc.dao;

import com.xy.biz.uc.domain.po.UserGroupUserRelPO;
import com.xy.biz.uc.domain.req.RemoveUserGroupUserRelRequest;
import org.springframework.util.CollectionUtils;

import java.util.Collection;
import java.util.List;
import java.util.Objects;
import java.util.stream.Collectors;

import static com.xy.biz.uc.domain.bo.UserGroupBO.JOIN_STATUS_JOINED;

/**
 *
 *
 * @author zsp
 * @date 2020-8-20
 */
public interface UserGroupUserRelDao {

	/**
	 * 保存多个
	 *
	 * @param collection
	 */
	int saveAllUserGroupUserRel(Collection<UserGroupUserRelPO> collection);

	/**
	 * 删除
	 *
	 * @param userGroupId
	 */
	int deleteUserGroupUserRelByUserGroupId(Long userGroupId);

	/**
	 * 删除
	 *
	 * @param userId
	 */
	int deleteUserGroupUserRelByUserId(Long userId);

	/**
	 * 删除
	 *
	 * @param request
	 */
	int deleteUserGroupUserRelByUserIdAndUserGroupId(RemoveUserGroupUserRelRequest request);

	/**
	 * 查找多条
	 *
	 * @param collection
	 * @return
	 */
	List<UserGroupUserRelPO> listUserGroupUserRelByUserGroupId(Collection<Long> collection);

	/**
	 * 查找多条
	 *
	 * @param collection
	 * @return
	 */
	List<UserGroupUserRelPO> listUserGroupUserRelByUserId(Collection<Long> collection);


	/// default methods

	/**
	 * 查找多条
	 *
	 * @param collection
	 * @return
	 */
	default List<UserGroupUserRelPO> listJoinUserGroupUserRelByUserGroupId(Collection<Long> collection) {
		List<UserGroupUserRelPO> list = listUserGroupUserRelByUserGroupId(collection);
		if(!CollectionUtils.isEmpty(list)) {
			return list.stream().filter(e -> Objects.equals(JOIN_STATUS_JOINED, e.getJoinStatus())).collect(Collectors.toList());
		}
		return list;
	}

	/**
	 * 查找多条
	 *
	 * @param collection
	 * @return
	 */
	default List<UserGroupUserRelPO> listJoinUserGroupUserRelByUserId(Collection<Long> collection) {
		List<UserGroupUserRelPO> list = listUserGroupUserRelByUserId(collection);
		if(!CollectionUtils.isEmpty(list)) {
			return list.stream().filter(e -> Objects.equals(JOIN_STATUS_JOINED, e.getJoinStatus())).collect(Collectors.toList());
		}
		return list;
	}

}
